﻿using AutoMapper;
using MediatR;
using S.Organization.API.Application.Command.CottageCommand;
using S.Organization.API.Application.Command.SubcultivationCommand;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;

namespace S.Organization.API.Application.CommandHandler.SubcultivationCommandHandler
{
    public class AddSubcultivationCommandHandler : IRequestHandler<AddSubcultivationCommand, int>
    {
        private readonly IBaseRepository<Subcultivation> _repository;
        private readonly IMapper mapper;

        public AddSubcultivationCommandHandler(IBaseRepository<Subcultivation> repository, IMapper mapper)
        {
            _repository = repository;
            this.mapper = mapper;
        }

        public async Task<int> Handle(AddSubcultivationCommand request, CancellationToken cancellationToken)
        {
            request.CreateBy = "张三";
            request.CreateDate = DateTime.Now;
            return await _repository.CreateAsync(mapper.Map<Subcultivation>(request));
        }
    }
}
